﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using DTO;

namespace DAO
{
    public class BC_MDP_DAO : ConnectionDAO
    {
        public static bool LapBC(long mBC, long tBC)
        {
            OleDbConnection cN = null;
            bool temp = true;

            try
            {
                cN = Cnect();

                string cmString = @"INSERT INTO BC_MDP(MaBC_MDP,ThangBaoCao) VALUES (@mBC,@tBC)";

                OleDbCommand cM = new OleDbCommand(cmString, cN);

                OleDbParameter thamSo;

                thamSo = new OleDbParameter("@mBC", OleDbType.Integer);
                thamSo.Value = mBC;
                cM.Parameters.Add(thamSo);

                thamSo = new OleDbParameter("@tBC", OleDbType.Integer);
                thamSo.Value = tBC;
                cM.Parameters.Add(thamSo);


                cM.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                temp = false;
            }
            finally
            {
                if (cN != null && cN.State == System.Data.ConnectionState.Open)
                    cN.Close();
            }

            return temp;
        }

        public static bool UpdateTSN(long mBC, long tSN)
        {
            bool temp = true;
            OleDbConnection cN = null;

            try
            {
                cN = Cnect();

                string cmString = @"UPDATE BC_MDP
                                    SET TongSoNgayThue=@tSN
                                    WHERE MaBC_MDP=@mBC";

                OleDbCommand cM = new OleDbCommand(cmString, cN);

                OleDbParameter thamSo;


                thamSo = new OleDbParameter("@tSN", OleDbType.Integer);
                thamSo.Value = tSN;
                cM.Parameters.Add(thamSo);


                thamSo = new OleDbParameter("@mBC", OleDbType.Integer);
                thamSo.Value = mBC;
                cM.Parameters.Add(thamSo);

                cM.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                temp = false;
            }
            finally
            {
                if (cN != null && cN.State == System.Data.ConnectionState.Open)
                    cN.Close();
            }

            return temp;
        }

        public static bool KtMaBC(long mBC)
        {
            OleDbConnection cN = null;
            long t = 0;

            try
            {
                cN = Cnect();

                string cmString = @"SELECT BC.MaBC_MDP
                                    FROM BC_MDP BC
                                    WHERE BC.MaBC_MDP=@mBC";

                OleDbCommand cM = new OleDbCommand(cmString, cN);

                OleDbParameter thamSo = new OleDbParameter("@mBC", OleDbType.Integer);
                thamSo.Value = mBC;
                cM.Parameters.Add(thamSo);

                OleDbDataReader rDer = cM.ExecuteReader();


                while (rDer.Read())
                {
                    if (!rDer.IsDBNull(0))
                        t = rDer.GetInt32(0);
                    else
                        t = 0;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (cN != null && cN.State == System.Data.ConnectionState.Open)
                    cN.Close();
            }

            if (t == 0)
            {
                return true;
            }
            return false;
        }
    }
}
